package com.kgar.entity.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;
import org.springframework.data.elasticsearch.core.suggest.Completion;

import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(indexName = "resume")
@Setting(settingPath = "/elasticsearch/settings.json")
public class ResumeDoc {
    @Id
    private String resumeId;

    private Integer userId;

    private String resumeName;

    private String name;

    private Boolean gender;

    private Integer age;

    private String maritalStatus;

    private String politStatus;

    @Field(type = FieldType.Text,analyzer = "text_analyzer",searchAnalyzer = "ik_smart",copyTo = "recommend")
    private String major;

    private String surname;

    private Date birthday;

    private String college;

    @Field(type = FieldType.Keyword,copyTo = "recommend")
    private String degree;

    private String race;

    private String nationality;

    @Field(type = FieldType.Keyword,copyTo = "recommend")
    private String englishLevel;

    @Field(type = FieldType.Keyword,copyTo = "recommend")
    private String computerLevel;

    private String phone;

    private String email;

    private String qq;

    private String weixin;

    private String expectSalary;

    @Field(type = FieldType.Keyword,copyTo = "recommend")
    private String expectSalaryMin;

    @Field(type = FieldType.Keyword,copyTo = "recommend")
    private String expectSalaryMax;
    private String expectJob;
    private String expectIndustry;

    private String livingAddress;

    @Field(type = FieldType.Text,analyzer = "text_analyzer",searchAnalyzer = "ik_smart")
    private List<String> educationObjs;
    @Field(type = FieldType.Text,analyzer = "text_analyzer",searchAnalyzer = "ik_smart")
    private List<String> jobExpObjs;
    @Field(type = FieldType.Text,analyzer = "text_analyzer",searchAnalyzer = "ik_smart")
    private List<String> projExpObjs;
    @Field(type = FieldType.Keyword,copyTo = "recommend")
    private List<String> skillsObjs;

    @Field(type = FieldType.Text,analyzer = "text_analyzer",searchAnalyzer = "ik_smart",copyTo = "recommend")
    private String contMyDesc;


    private String link;

    @Field(type = FieldType.Date)
    private Date savedTime;


    @Field(type = FieldType.Text,analyzer = "text_analyzer",searchAnalyzer = "ik_smart",copyTo = "recommend")
    private String rawText;

    @Field(type = FieldType.Text,analyzer = "text_analyzer",searchAnalyzer = "ik_smart")
    private String recommend;

    @CompletionField(analyzer = "completion_analyzer")
    private Completion suggestion;


    public ResumeDoc(Resume resume) {
        this.resumeId = resume.getResumeId().toString();
        this.userId = resume.getUserId();
        this.resumeName = resume.getResumeName();
        this.name = resume.getName();
        this.gender = resume.getGender();
        this.age = resume.getAge();
        this.maritalStatus = resume.getMaritalStatus();
        this.politStatus = resume.getPolitStatus();
        this.major = resume.getMajor();
        this.surname = resume.getSurname();
        this.birthday = resume.getBirthday();
        this.college = resume.getCollege();
        this.degree = resume.getDegree();
        this.race = resume.getRace();
        this.nationality = resume.getNationality();
        this.englishLevel = resume.getEnglishLevel();
        this.computerLevel = resume.getComputerLevel();
        this.phone = resume.getPhone();
        this.email = resume.getEmail();
        this.qq = resume.getQq();
        this.weixin = resume.getWeixin();
        this.expectSalary = resume.getExpectSalary();
        this.expectSalaryMin = resume.getExpectSalaryMin();
        this.expectSalaryMax = resume.getExpectSalaryMax();
        this.expectJob = resume.getExpectJob();
        this.expectIndustry = resume.getExpectIndustry();
        this.livingAddress = resume.getLivingAddress();
        this.educationObjs = resume.getEducationObjs().stream().map(EducationExp::getEduContent).toList();
        this.jobExpObjs = resume.getJobExpObjs().stream().map(JobExp::getJobContent).toList();;
        this.projExpObjs = resume.getProjExpObjs().stream().map(ProjExp::getProjContent).toList();;
        this.skillsObjs = resume.getSkillsObjs().stream().map(Skills::getSkillsName).toList();;
        this.rawText = resume.getRawText();
        this.contMyDesc = resume.getContMyDesc();
        this.link = resume.getLink();
        this.savedTime = new Date(resume.getSavedTime().getTime());
        this.suggestion = new Completion();
        this.suggestion.setInput(new String[]{resume.getRawText()});
    }

}
